<template>
  <div id="CyclecostDetalis">
    <v-detail
      :detailData="inputData.detailData"
      :inputConfig="inputConfig"
      :rules="rules"
      ref="input"
    ></v-detail>
  </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "CyclecostDetalis",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object
    }
  },
  data () {
    return {
      rules: {
        cartonizeft: [
          { validator: this.verify, trigger: 'blur' },
        ],
        reorderpoint: [
          { validator: this.verify, trigger: 'blur' },
        ],
        stdordercost: [
          { validator: this.verify, trigger: 'blur' },
        ],
        groupfteach: [
          { validator: this.verify1, trigger: 'blur' },
        ],
        reorderqty: [
          { validator: this.verify1, trigger: 'blur' },
        ],
      },
      whseidflag: true
    }
  },
  computed: {
    inputConfig () {
      return [
        [
          {
            type: "select",
            label: this.$t('config.cycleLevel'),
            props: "abc",
            options: this.getOptions('queryCcsetupDropDown'),
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.lastCycle'),
            props: "lastcyclecount",
            disabled: this.whseidflag
          },
          {
            type: "select",
            label: this.$t('config.ccdiscrepancyrule'),
            props: "ccdiscrepancyrule",
            options: this.getOptions('queryCcadjrulesDropDown'),
            disabled: this.whseidflag
          },
        ],
        [
          {
            type: "input",
            label: this.$t('config.reorderqty'),
            props: "reorderqty",
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.reorderpoint'),
            props: "reorderpoint",
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.stdordercost'),
            props: "stdordercost",
            disabled: this.whseidflag
          },
        ],
        [
          {
            type: "input",
            label: this.$t('config.flowthruitem'),
            props: "flowthruitem",
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.cartonizeft'),
            props: "cartonizeft",
            disabled: this.whseidflag
          },
          {
            type: "input",
            label: this.$t('config.groupfteach'),
            props: "groupfteach",
            disabled: this.whseidflag
          }
        ]
      ]
    }
  },
  methods: {
    verify (rule, value, callback) {
      if (value === '') {
        this.$message.error(this.$t('app.dataIsNotNull'))
        callback(new Error());
      } else {
        var re = /[^0-9.]/;
        let te = value;
        let flag = re.test(te)
        if (!flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputNumberPlease'))
            this.inputData.detailData[rule.field] = 0
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputNumberPlease'))
          this.inputData.detailData[rule.field] = 0
          callback(new Error());
        }
      }
    },
    verify1 (rule, value, callback) {
      if (value === '') {
        callback(new Error());
      } else {
        var re = /^[0-9]*$/;
        let te = value;
        let flag = re.test(te)
        if (flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
            this.inputData.detailData[rule.field] = 0
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
          this.inputData.detailData[rule.field] = 0
          callback(new Error());
        }
      }
    },
  },
  mounted () {
    if (this.$store.state.wms.toUpperCase().includes('WMWHSE')) {
      //仓库级
      this.whseidflag = false;
    }
  },
  components: {
    "v-detail": detail
  }
}
</script>

<style scoped>
</style>
